import Vue from 'vue'
import VueRouter from 'vue-router'


import Home from '@/views/home/home.vue'

import Introduce from '@/views/introduce/introduce.vue'
import KnowMore from '@/views/KnowMore/KnowMore.vue'

// 简历投递，我的简历，进度查询
import Deliver from '@/views/deliver/deliver.vue'
import Dropresume from '@/views/deliver/Dropresume.vue'
import Messtake from '@/views/deliver/Messtake.vue'


import Login from '@/views/login/login.vue'
import ForgetPwd from '@/views/login/forgetPwd.vue'
import RegisterMessage from '@/views/login/registerMessage.vue'

Vue.use(VueRouter)

// 将需要登录才能进入的进行判断，通过添加字段 gorouter

const routes = [
  { path: '/', redirect: '/home' },
  { path: '/home', component: Home },
  { path: '/introduce', component: Introduce },
  { path: '/knowmore', component: KnowMore },

  {
    path: '/deliver',
    component: Deliver,
    meta: {
      gorouter: true
    }
  },
  {
    path: '/dropresume',
    component: Dropresume,
    meta: {
      gorouter: true
    }
  },
  {
    path: '/messtake',
    component: Messtake,
    meta: {
      gorouter: true
    }
  },
  { path: '/login', component: Login },
  // 忘记密码
  {
    path: '/forgetPwd',
    component: ForgetPwd
  },
  // 立即注册
  {
    path: '/registerMessage',
    component: RegisterMessage
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  // 判断该路由是否需要权限
  if (to.meta.gorouter) {
    // 判断是否有登录信息
    if (localStorage.Authorization) {
      next()
    } else {
      next({
        path: '/login'
        // 将该路由path传入login页面，登录成功后跳转到该页面
        // query: { redirect: to.fullPath },
      })
    }
  } else {
    next()
  }
})

export default router
